package sjtu.ist.warehouse4ws.action;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.Department;
import sjtu.ist.warehouse4ws.model.Fileinfo;
import sjtu.ist.warehouse4ws.service.DepartmentService;
import sjtu.ist.warehouse4ws.service.FileInfoService;
import sjtu.ist.warehouse4ws.vo.FullSearchVO;

import org.apache.struts2.json.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowDetailSearchAction extends ActionSupport{
	private FileInfoService fileInfoService;
	private List<FullSearchVO> fileList = new ArrayList<FullSearchVO>();
	
	private List <Department> departmentList=new ArrayList<Department> ();
	private DepartmentService departmentService;

	private String keyWord1;
	private String keyWord2;
	private String keyWord3;
	private String keyWord4;
	private String keyWord5;
	private String keyWord6;
	
	//获得Search结果列表
	public String showDetailSearchFileList(){
		System.out.println("ShowDetailSearchAction");
		//System.out.println(keyWord5);
//		this.fileList = fileInfoService.getAllDetailSearchResult(keyWord1,keyWord2,keyWord3,
//													keyWord4,keyWord5,keyWord6);
		
		try {
			if(keyWord1 != null){
			keyWord1 = new String(keyWord1.getBytes("ISO-8859-1"), "UTF-8");}
			if(keyWord2 != null){
			keyWord2 = new String(keyWord2.getBytes("ISO-8859-1"), "UTF-8");}
			//keyWord3 = new String(keyWord3.getBytes("ISO-8859-1"), "UTF-8"); 
			if(keyWord4 != null){
			keyWord4 = new String(keyWord4.getBytes("ISO-8859-1"), "UTF-8");}
			if(keyWord5 != null){
			keyWord5 = new String(keyWord5.getBytes("ISO-8859-1"), "UTF-8");} 
			//keyWord6 = new String(keyWord6.getBytes("ISO-8859-1"), "UTF-8"); 
			} catch (UnsupportedEncodingException e) { 
			// TODO 自动生成 catch 块 
			e.printStackTrace(); 
			} 


		this.fileList = fileInfoService.getAllDetailSearchResult(keyWord1,keyWord2,keyWord3,
				keyWord4,keyWord5,keyWord6);
		
		System.out.println(fileList.size());
		return SUCCESS;
	}
	
	//具体显示哪些内容有待修改~JSON再问问！
	@JSON(name = "totalFile")
	public int getTotalFile() {
		return this.fileList.size();
	}

	@JSON(name = "File")
	public List<FullSearchVO> getFileList() {
		return this.fileList;
	}
	
	public void setFileList(List<FullSearchVO> fileList) {
		this.fileList = fileList;
	}
	
	// 注入FileInfoService
	public void setFileInfoService(FileInfoService fileInfoService) {
		this.fileInfoService = fileInfoService;
	}

	public String getKeyWord1() {
		return keyWord1;
	}

	public void setKeyWord1(String keyWord1) {
		this.keyWord1 = keyWord1;
	}
	public String getKeyWord2() {
		return keyWord2;
	}

	public void setKeyWord2(String keyWord2) {
		this.keyWord2 = keyWord2;
	}

	public String getKeyWord3() {
		return keyWord3;
	}

	public void setKeyWord3(String keyWord3) {
		this.keyWord3 = keyWord3;
	}

	public String getKeyWord4() {
		return keyWord4;
	}

	public void setKeyWord4(String keyWord4) {
		this.keyWord4 = keyWord4;
	}

	public String getKeyWord5() {
		return keyWord5;
	}

	public void setKeyWord5(String keyWord5){
		this.keyWord5 = keyWord5;
	}

	public String getKeyWord6() {
		return keyWord6;
	}

	public void setKeyWord6(String keyWord6) {
		this.keyWord6 = keyWord6;
	}
}